package com.atguigu.gulimall.order.vo;

import com.atguigu.common.tool.utils.Func;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @author : wenchao.long
 * @date : Created in 2021/8/18 19:16 周三
 * @description :
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderConfirmVO {

    @ApiModelProperty("收货地址")
    List<MemberAddressVO> address;

    @ApiModelProperty("所有选中的购物项")
    List<OrderItemVO> items;

    @ApiModelProperty("发票信息")
    String ll;

    @ApiModelProperty("优惠券")
    private Integer integration;

    @ApiModelProperty("订单总额")
    private BigDecimal total;

    @ApiModelProperty("应付价格")
    private BigDecimal payPrice;

    @ApiModelProperty("防重令牌")
    private String orderToken;

    private Integer count;

    private Map<Long, Boolean> stocks;

    public BigDecimal getTotal() {
        BigDecimal total = new BigDecimal("0");
        if (Func.isNotEmpty(items)) {
            for (OrderItemVO item : items) {
                total = total.add(item.getTotalPrice());
            }
        }
        return total;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    public Integer getCount() {
        return Func.isNotEmpty(items) ? items.stream().mapToInt(OrderItemVO::getCount).sum() : null;
    }
}
